using System;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    public class RequiredObjectRuleTest
    {


        const string expectedErrorMessage = "expectedErrorMessage";
        const string expectedRuleSet = "EXPECTEDRULESET";
        const string expectedInitialValue = "a";
        [TestFixture]
        public class Construction
        {
            [Test]
            public void Simple1()
            {
                var rule = new RequiredRule<object>(expectedErrorMessage, false, expectedInitialValue);
                Assert.AreEqual(expectedInitialValue, rule.InitialValue);
                Assert.IsTrue(rule.HasInitialValue);
                Assert.AreEqual(expectedErrorMessage, rule.ErrorMessage);
                Assert.IsFalse(rule.UseErrorMessageProvider);
            }
            [Test]
            [ExpectedException(typeof(ArgumentNullException), ExpectedMessage = "Value cannot be null.\r\nParameter name: initialValue")]
            public void Construction1InitialValueNull()
            {
                new RequiredRule<object>(expectedErrorMessage, false, null);
            }


            [Test]
            public void Simple2()
            {
                var rule = new RequiredRule<object>(expectedErrorMessage, false);
                Assert.IsFalse(rule.HasInitialValue);
                Assert.AreEqual(expectedErrorMessage, rule.ErrorMessage);
                Assert.IsFalse(rule.UseErrorMessageProvider);
            }


            [Test]
            public void Simple3()
            {
                var rule = new RequiredRule<object>(expectedErrorMessage);
                Assert.IsFalse(rule.HasInitialValue);
                Assert.AreEqual(expectedErrorMessage, rule.ErrorMessage);
                Assert.IsFalse(rule.UseErrorMessageProvider);
            }


            [Test]
            public void Simple4()
            {
                var rule = new RequiredRule<object>();
                Assert.IsFalse(rule.HasInitialValue);
                Assert.IsNull(rule.ErrorMessage);
                Assert.IsFalse(rule.UseErrorMessageProvider);
            }
        }
        [TestFixture]
        public class Validate
        {
            [Test]
            public void Simple()
            {
                var rule = new RequiredRule<object>(null, false);
                rule.CheckType(new MockInfoDescriptor(typeof(object).TypeHandle, "foo"));

                Assert.IsNotNull(rule.Validate(null, null, null, null));
                Assert.IsNull(rule.Validate(null, "s", null, null));

                var nullableRule2 = new RequiredStringRule(null, false, "a", true, true);
                Assert.IsNotNull(nullableRule2.Validate(null, "a", null, null));
                Assert.IsNull(nullableRule2.Validate(null, "s", null, null));
            }
        }
        [TestFixture]
        public class RuleInterpretation
        {
            [Test]
            public void Simple()
            {

                var nullableRule = new RequiredRule<object>(null, false);
                Assert.IsNotNull(nullableRule.RuleInterpretation);

            }
        }

    }
}